<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>闲言轻博客</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
{{template "comm/link.html"}}
</head>
<body class="lay-blog">
{{template "comm/header.html".}}
<div class="container-wrap">
    <div class="container">
        <div class="contar-wrap">
            <h4 class="item-title">
                <p><i class="layui-icon layui-icon-speaker"></i>公告：<span>欢迎来到我的轻博客</span></p>
            </h4>
        {{range .notes}}
            <div class="item">
                <div class="item-box  layer-photos-demo1 layer-photos-demo">
                    <h3><a href="/details/{{.Key}}">{{.Title}}</a></h3>
                    <h5>发布于：<span>{{date .UpdatedAt "Y-m-d H:i:s"}}</span></h5>
                    <p>
                    {{str2html .Summary}}
                    </p>
                </div>
                <div class="comment count">
                    <a href="/details/{{.Key}}#comment">评论</a>
                    <a href="javascript:;" class="like" data-key="{{.Key}}" data-type="note">点赞</a>
                </div>
            </div>
        {{end}}
        </div>
        <div class="item-btn">
        {{if gt .page 1}}
            <button id="prePageBtn" class="layui-btn layui-btn-normal">上一页
            </button>
        {{end}}
        {{if lt .page .totpage}}
            <button id="nextPageBtn" class="layui-btn layui-btn-normal">下一页
            </button>
        {{end}}
        </div>
    </div>
</div>
{{template "comm/footer.html" .}}
<script>
    layui.use(['jquery', 'util'], function () {
        var util = layui.util,
                $ = layui.jquery;
        //执行
        var option = {};
    {{if and (.IsLogin)  (eq2 .User.Role 0) }}
        option = {
            bar1: '&#xe654;',
            click: function (type) {
                console.log(type);
                if (type === 'bar1') {
                {{if .IsLogin }}
                    window.location.href = "/note/new";
                {{else}}
                    window.location.href = "/user";
                {{end}}
                }
            }
        };
    {{else if not .IsLogin}}
        option = {
            bar1: '&#xe770;',
            click: function (type) {
                if (type === 'bar1') {
                    window.location.href = "/user";
                }
            }
        };
    {{end}}
        util.fixbar(option);
        $("#nextPageBtn").on("click", function () {
            var nextpage = {{.page}}+1;
            if (nextpage >{{.totpage}}) {
                layer.msg("没有下一页", {icon: 5})
            } else {
                window.location.href = "/?page=" + nextpage + "&title={{.title}}"
            }
        });
        $("#prePageBtn").on("click", function () {
            var nextpage = {{.page}}-1;
            if (nextpage <= 0) {
                layer.msg("没有上一页", {icon: 5})
                return;
            }
            window.location.href = "/?page=" + nextpage + "&title={{.title}}"
        });
    });
</script>
</body>
</html>